/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘国水
 * Date: 2025-04-26
 * Time: 9:49
 */
public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode first;

    public ListNode last;

    /**
     * 入队操作： 尾插法
     * @param val
     */
    public void offer(int val) {
        ListNode node = new ListNode(val);
        if(first == null) {
            first = node;
        } else {
            last.next = node;
            node.prev = last;
            node = last;
        }
    }

    /**
     * 获取队头元素删除
     * @return
     */
    public int poll() {
        if(first == last) {
            first = last = null;
        }
        int ret = first.val;
        first = first.next;
        first.prev = null;
        return ret;
    }
}
